﻿using DistributeTransaction.Models;
using DistributeTransaction.Utils;
using log4net;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Web;

namespace DistributeTransaction.DAL
{
    public class DatabaseContext : DbContext
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(DatabaseContext));

        public DatabaseContext()
            : base("DatabaseContext")
        {
            this.Configuration.LazyLoadingEnabled = false;

            this.Database.Log = (s) =>
            {
                if (!string.IsNullOrEmpty(StringUtils.Trim(s)))
                    log.Info(s);
            };
        }

        public DbSet<Order> Orders { get; set; }
        public DbSet<OrderDetail> OrderDetail { get; set; }
        public DbSet<Product> Products { get; set; }
        public DbSet<ShoppingCart> ShoppingCarts { get; set; }
        public DbSet<WatchList> WatchLists { get; set; }
        public DbSet<Payment> Payments { get; set; }
        public DbSet<Customer> Customers { get; set; }
        public DbSet<CardInfo> CardInfos { get; set; }
        public DbSet<Category> Categorys { get; set; }
        public DbSet<OrderSummary> OrderSummarys { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            //modelBuilder.Entity<Order>()
            //   .HasOptional(p => p.UserId).WithRequired(p => p.UserId);
        }
    }
    
}